package com.sunrise.xdoc.entity.contact;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.validator.constraints.Length;

import com.sunrise.xdoc.entity.employee.CaLamViec;

@Entity
@Table(name = "contact_nhan_vien")
@Inheritance(strategy = InheritanceType.JOINED)
public class NhanVien extends AbstractContact {
	private static final long serialVersionUID = -1637510501381725480L;
	private String cmnd;
	private LoaiNhanVien loai;
	private long luongThang = 0;
	private Set<CaLamViec> caLamViecs = new HashSet<>();

	@Column(name = "cmnd", unique = true)
	@Length(max = 20)
	public String getCmnd() {
		return cmnd;
	}

	public void setCmnd(String cmnd) {
		this.cmnd = cmnd;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "loai_nhan_vien_id")
	public LoaiNhanVien getLoai() {
		return loai;
	}

	public void setLoai(LoaiNhanVien loai) {
		this.loai = loai;
	}

	@Column(name = "luong_thang")
	public long getLuongThang() {
		return luongThang;
	}

	public void setLuongThang(long luongThang) {
		this.luongThang = luongThang;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "at_nhan_vien_ca", joinColumns = { @JoinColumn(name = "nhan_vien_id") }, inverseJoinColumns = { @JoinColumn(name = "ca_id") })
	public Set<CaLamViec> getCaLamViecs() {
		return caLamViecs;
	}

	public void setCaLamViecs(Set<CaLamViec> caLamViecs) {
		this.caLamViecs = caLamViecs;
	}
}
